/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class ParserOptions {
  sourceType: string = 'script';

  sourceFilename?: string;

  startLine: number = 1;

  allowReturnOutsideFunction: boolean = false;

  allowImportExportEverywhere: boolean = false;

  allowSuperOutsideMethod: boolean = false;

  plugins: string[] = [];

  strictMode?: boolean = undefined;

  ranges: boolean = false;
}

let defaultOptions = new ParserOptions();

function getOptions(opts?: ParserOptions): ParserOptions {
  const options: ParserOptions = new ParserOptions();
  if (opts !== null && opts !== undefined) {
    if (opts.sourceType) {
      options.sourceType = opts.sourceType;
    }
    if (opts.sourceFilename) {
      options.sourceFilename = opts.sourceFilename;
    }
    if (opts.startLine) {
      options.startLine = opts.startLine;
    }
    if (opts.allowReturnOutsideFunction !== null) {
      options.allowReturnOutsideFunction = opts.allowReturnOutsideFunction;
    }
    if (opts.allowImportExportEverywhere !== null) {
      options.allowImportExportEverywhere = opts.allowImportExportEverywhere;
    }
    if (opts.allowSuperOutsideMethod != null) {
      options.allowSuperOutsideMethod = opts.allowSuperOutsideMethod;
    }
    if (opts.plugins) {
      options.plugins = opts.plugins;
    }
    if (opts.strictMode != null) {
      options.strictMode = opts.strictMode;
    }
    if (opts.ranges != null) {
      options.ranges = opts.ranges;
    }
  }
  return options;
}

export { getOptions, ParserOptions, defaultOptions };
